package com.dao.impl;

import com.bean.Enterprise;
import com.dao.EnterpriseDao;

import java.util.List;

public class EnterpriseDaoImpl extends BaseDao implements EnterpriseDao {

    @Override
    public Enterprise queryEnterpriseByEnterpriseidAndPassword(String enterpriseid, String password) {
        String sql="select `enterpriseid`,`enterprise_name`,`head_sculpture`,`address`,`telephone`,`password`,`relname` from enterprise where enterpriseid=? and password=?";
        return queryForOne(Enterprise.class, sql, enterpriseid,password);
    }

    @Override
    public int saveEnterprise(Enterprise enterprise) {
        String sql="insert into enterprise(`enterpriseid`,`enterprise_name`,`head_sculpture`,`address`,`telephone`,`password`,`relname`)values(?,?,?,?,?,?,?)";
        return update(sql,enterprise.getEnterpriseid(),enterprise.getEnterprise_name(),enterprise.getHead_sculpture(),enterprise.getAddress(),enterprise.getTelephone(),enterprise.getPassword(),enterprise.getRelname());
    }

    @Override
    public Enterprise existsEnterpriseid(String enterpriseid) {
        String sql="select `enterpriseid`,`enterprise_name`,`head_sculpture`,`address`,`telephone`,`password`,`relname` from enterprise where enterpriseid=?";
        return queryForOne(Enterprise.class,sql,enterpriseid);
    }

    @Override
    public Enterprise queryEnterpriseByEnterpriseid(String enterpriseid) {
        String sql="select `enterpriseid`,`enterprise_name`,`head_sculpture`,`address`,`telephone`,`password`,`relname` from enterprise where enterpriseid=?";
        return queryForOne(Enterprise.class, sql, enterpriseid);
    }

    @Override
    public int updatePass(String enterpriseid, String password) {
        String sql="update enterprise set `password`=? where enterpriseid=?";
        return update(sql,password,enterpriseid);
    }

    @Override
    public int updateMess(String enterpriseid, String enterprise_name, String relname, String telephone, String address) {
        String sql="update enterprise set `enterprise_name`=?,`address`=?,`telephone`=?,`relname`=? where enterpriseid=? ";
        return update(sql,enterprise_name,address,telephone,relname,enterpriseid);
    }

    @Override
    public int updatePhoto(String enterpriseid, String head_sculpture) {
        String sql="update enterprise set `head_sculpture`=? where enterpriseid=?";
        return update(sql,head_sculpture,enterpriseid);
    }

    @Override
    public int delete(String enterpriseid) {
        String sql="delete from enterprise where enterpriseid=?";
        return update(sql,enterpriseid);
    }

    @Override
    public Integer queryForPageTotalCount() {
        String sql="select count(*) from enterprise";
        Number count= (Number) queryForSingleValue(sql);
        return count.intValue();
    }

    @Override
    public List<Enterprise> queryForPageItem(int begin, int pageSize) {
        String sql="select `enterpriseid`,`enterprise_name`,`head_sculpture`,`address`,`telephone`,`password`,`relname` from enterprise limit ?,?";
        return queryForList(Enterprise.class,sql, begin,pageSize);
    }

    @Override
    public Enterprise showMess(String enterpriseid) {
        String sql="select `enterpriseid`,`enterprise_name`,`head_sculpture`,`address`,`telephone`,`password`,`relname` from enterprise where enterpriseid=?";

        return queryForOne(Enterprise.class,sql,enterpriseid);
    }
}
